﻿using System;

namespace DX
{
    [System.AttributeUsage(System.AttributeTargets.Class| System.AttributeTargets.Interface, Inherited = false, AllowMultiple = true)]
   public  sealed class ViewTypeAttribute : System.Attribute
    {
        public ViewTypeAttribute(Type viewType)
        {
            if (viewType == null) throw new ArgumentNullException(nameof( viewType));
            ViewType = viewType;
            ViewName = "default";
        }
        public ViewTypeAttribute(Type viewType,string viewName)
        {
            if (viewType == null) throw new ArgumentNullException(nameof(viewType));
            if (string.IsNullOrEmpty(viewName))
            {
                throw new ArgumentException($"“{nameof(viewName)}”不能为 null 或空。", nameof(viewName));
            }

            ViewType = viewType;
            ViewName = viewName;
        }
        public ViewTypeAttribute(string viewType):this(Type.GetType(viewType))
        {
            if(ViewType ==null) throw new ViewNotFoundException(viewType);
       
        }
        public Type ViewType { get; }
        public string ViewName { get; set; }
    }
}